package com.yc.autouser.controller;


import com.yc.autouser.service.EmailCodeService;
import com.yc.common.expection.BaseException;
import com.yc.common.res.ResultClass;
import com.yc.common.utils.BasicsUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
/**
 * @Classname EmailCodeController
 * @Description 邮箱验证码发送
 * @Version 1.0.0
 * @Date 2022/7/19 9:27
 * @Created by jiesen
 */
@Controller
public class EmailCodeController {
    @Resource
    private EmailCodeService emailCodeService;

    @RequestMapping("/emailCode")
    @ResponseBody
    public ResultClass emailCodeCreate(String email) {
        String emailCode = BasicsUtils.getVerificationCode();//生成6位随机验证码
        //先存redis再发送到用户
        try {
            emailCodeService.emailCodeSend(email, emailCode);
        } catch (BaseException e) {
            return ResultClass.fail(500, "服务器内部错误");
        }

        return ResultClass.success();

    }
}
